home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / textdt / textdt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-16  |  3.8 KB  |  140 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // TextDT.cpp
  3. //
  4. // Deryk Robosson
  5. // March 17, 1996
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/TextDT.hpp"
  11.  
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. AFTextDT::AFTextDT()
  16. {
  17.     m_dtText.buffer=NULL;
  18.     m_dtText.bufferlen=0;
  19.     m_dtText.linelist=NULL;
  20.     m_dtText.tf=NULL;
  21. }
  22.  
  23. AFTextDT::~AFTextDT()
  24. {
  25. }
  26.  
  27. // Create new object
  28. BOOL AFTextDT::LoadText(char *file_name, struct Screen *screen)
  29. {
  30.     struct Screen   *scr;
  31.  
  32.     if(m_dtGlobal.o != NULL) {
  33.         if(m_dtGlobal.dtAdded)
  34.             RemoveObject();
  35.         DisposeDTObject(m_dtGlobal.o);
  36.         delete m_dtGlobal.o;
  37.         m_dtGlobal.o=NULL;
  38.     }
  39.  
  40.     if(!(IsDataType(file_name)))
  41.         return FALSE;
  42.  
  43.     // Get font info from the screen we are on or are passed
  44.     if(!screen) {
  45.         if(scr=LockPubScreen(NULL)) {
  46.             AskFont(&scr->RastPort,&m_dtText.ta);
  47.             UnlockPubScreen(NULL,scr);
  48.         }
  49.     } else AskFont(&screen->RastPort,&m_dtText.ta);
  50.  
  51.     // Set our new DataType Object
  52.     if(!(m_dtGlobal.o=NewDTObject(file_name,DTA_SourceType,DTST_FILE,
  53.                                   GA_Immediate, TRUE,
  54.                                   GA_RelVerify, TRUE,
  55.                                   DTA_GroupID,GID_TEXT,
  56.                                   DTA_TextAttr, &m_dtText.ta,
  57.                                   TDTA_WordWrap, TRUE,
  58.                                   ICA_TARGET, ICTARGET_IDCMP,
  59.                                   TAG_DONE)))
  60.         return FALSE;
  61.  
  62.     // Get Attributes for our newly defined object
  63.     if(!(GetDTAttrs(m_dtGlobal.o,TDTA_LineList,&m_dtText.linelist,TAG_DONE)))
  64.         return FALSE;
  65.     else {
  66.         // Layout our new object
  67.         m_dtGlobal.gpl.MethodID=DTM_PROCLAYOUT;
  68.         m_dtGlobal.gpl.gpl_GInfo=NULL;
  69.         m_dtGlobal.gpl.gpl_Initial=1;
  70.  
  71.         if(!(DoMethodA(m_dtGlobal.o,(Msg)&m_dtGlobal.gpl)))
  72.             return FALSE;
  73.         else return TRUE;
  74.     }
  75. }
  76.  
  77. // Get buffer and return to user
  78. UBYTE* AFTextDT::GetBuffer(UBYTE* buffer)
  79. {
  80.     if(m_dtGlobal.o != NULL) {
  81.         if(!(GetDTAttrs(m_dtGlobal.o,TDTA_Buffer,&buffer,TAG_DONE))) {
  82.             buffer=NULL;
  83.             return buffer;
  84.         }
  85.         else return buffer;
  86.     } else {
  87.         buffer=NULL;
  88.         return buffer;
  89.       }
  90. }
  91.  
  92. // Return buffer size to user
  93. ULONG AFTextDT::GetBufferSize()
  94. {
  95.     return m_dtText.bufferlen;
  96. }
  97.  
  98. // Set new buffer for object
  99. BOOL AFTextDT::SetBuffer(UBYTE* buffer, ULONG size)
  100. {
  101.     if(m_dtGlobal.o != NULL) {
  102.         if(!(SetDTAttrs(m_dtGlobal.o,m_dtGlobal.dtWindow->m_pWindow,(struct Requester*)NULL,
  103.                     TDTA_Buffer,&buffer,TDTA_BufferLen,size,TAG_DONE)))
  104.             return FALSE;
  105.         else {
  106.             m_dtText.buffer=(char*)buffer;
  107.             m_dtText.bufferlen=size;
  108.             return TRUE;
  109.         }
  110.     } else return FALSE;
  111. }
  112.  
  113. // Set the font for the object
  114. BOOL AFTextDT::SetDTFont(struct TextFont *tf)
  115. {
  116.     if(m_dtGlobal.o != NULL) {
  117.         if(!(SetDTAttrs(m_dtGlobal.o,m_dtGlobal.dtWindow->m_pWindow,(struct Requester*)NULL,
  118.                         DTA_TextFont,tf,TAG_DONE)))
  119.             return FALSE;
  120.         else {
  121.             m_dtText.tf=tf;
  122.             return TRUE;
  123.         }
  124.     } else return FALSE;
  125. }
  126.  
  127. // set font attributes for object
  128. BOOL AFTextDT::SetDTFontAttr(TEXTATTR ta)
  129. {
  130.     if(m_dtGlobal.o != NULL) {
  131.         if(!(SetDTAttrs(m_dtGlobal.o,m_dtGlobal.dtWindow->m_pWindow,(struct Requester*)NULL,
  132.                         DTA_TextAttr,&ta,TAG_DONE)))
  133.             return FALSE;
  134.         else {
  135.             m_dtText.ta=ta;
  136.             return TRUE;
  137.         }
  138.     } else return FALSE;
  139. }
  140.